﻿using UnityEngine;
using System.Collections;

public class shoot : MonoBehaviour {
	public GameObject pre; //预制弹孔
	public float range=100.0f;//距离
	 int shootlay;
	Ray shotray;
	RaycastHit shoothit;
	// Use this for initialization
	void Start () {
		shootlay = LayerMask.GetMask ("Default");


	}
	
	// Update is called once per frame
	void Update () {
		if (Input.GetMouseButtonDown (0)) {
			shotray = Camera.main.ScreenPointToRay (Input.mousePosition);
			if(Physics.Raycast(shotray,out shoothit,range))
			   {
				Vector3 pos=shoothit.point;
				pos.z-=0.001f;

				GameObject hole=Instantiate(pre,pos,Quaternion.identity) as GameObject;
				//向前
				hole.transform.rotation=Quaternion.LookRotation(shoothit.normal);
				hole.transform.Rotate(90,0,0);
				hole.transform.Rotate(0,Random.Range(0,180),0);
				//hole.transform.localScale=new Vector3(0.3f,0.3f,0.3f);
				hole.transform.parent=shoothit.transform;

			}
		}
	
	}
}
/*   GameObject gameObj = hitInfo.collider.gameObject;
      Debug.Log("click object name is " + gameObj.name);
      gameObj.tag == "boot" 当射线碰撞目标为boot类型的物品 ，执行拾取操作*/